package com.hzyl.famousreader.view.activity;

import android.content.DialogInterface;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.SPUtils;
import com.umeng.analytics.MobclickAgent;
import com.hzyl.famousreader.Constant;
import com.hzyl.famousreader.R;
import com.hzyl.famousreader.router.Router;
import com.hzyl.famousreader.databinding.*;
import com.zhengsr.viewpagerlib.bean.PageBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 引导页
 */
@Route(path = Router.ACTIVITY_GUIDE)
public class GuideActivity extends AppCompatActivity {

  private boolean falg1;
  private boolean falg2;

  private ActivityGuideBinding binding;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    binding = DataBindingUtil.setContentView(GuideActivity.this, R.layout.activity_guide);

    binding.btnStart.setOnClickListener(v -> {

      //弹出用户协议洛
      commonDialog1("用户协议", Constant.yhxy);
      //两个用户协议



    });

    List<Integer> imgResIds = new ArrayList<>();
    imgResIds.add(R.mipmap.img_guide_01);
    imgResIds.add(R.mipmap.img_guide_02);
    imgResIds.add(R.mipmap.img_guide_03);
    imgResIds.add(R.mipmap.img_guide_04);

    PageBean pageBean = new PageBean.Builder<Integer>()
      .setDataObjects(imgResIds).setIndicator(binding.indicator).setOpenView(binding.btnStart).builder();

    binding.viewPager.setPageListener(pageBean, R.layout.activity_guide_content, (View view, Object o) -> {
      ImageView imageView = view.findViewById(R.id.image);
      imageView.setImageResource((Integer) o);
    });
  }

  @Override
  protected void onPause() {
    super.onPause();
    MobclickAgent.onPageEnd("引导页");
    MobclickAgent.onPause(this);
  }

  @Override
  protected void onResume() {
    super.onResume();
    MobclickAgent.onPageStart("引导页");
    MobclickAgent.onResume(this);
  }


  private void commonDialog1(String title, String message) {

    boolean flag = false;
    AlertDialog.Builder builder = new AlertDialog.Builder(GuideActivity.this);
    builder.setTitle(title);// 设置标题
    // builder.setIcon(R.drawable.ic_launcher);//设置图标
    builder.setMessage(message);// 为对话框设置内容
    // 为对话框设置取消按钮
    builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

      @Override
      public void onClick(DialogInterface arg0, int arg1) {
        // TODO Auto-generated method stub


      }
    });
    builder.setPositiveButton("同意", new DialogInterface.OnClickListener() {

      @Override
      public void onClick(DialogInterface arg0, int arg1) {
        commonDialog2(" 隐私政策", Constant.yszc);
      }
    });
    builder.create().show();// 使用show()方法显示对话框

  }


  private void commonDialog2(String title, String message) {

    boolean flag = false;
    AlertDialog.Builder builder = new AlertDialog.Builder(GuideActivity.this);
    builder.setTitle(title);// 设置标题
    // builder.setIcon(R.drawable.ic_launcher);//设置图标
    builder.setMessage(message);// 为对话框设置内容
    // 为对话框设置取消按钮
    builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

      @Override
      public void onClick(DialogInterface arg0, int arg1) {


      }
    });
    builder.setPositiveButton("同意", new DialogInterface.OnClickListener() {

      @Override
      public void onClick(DialogInterface arg0, int arg1) {
        SPUtils.getInstance().put(Constant.SP_BE_GUIDED, true);
        ARouter.getInstance().build(Router.ACTIVITY_MAIN).navigation();
        finish();
      }
    });
    builder.create().show();// 使用show()方法显示对话框

  }


}
